# flake8: NOQA

# 变量的使用

"""
# 使用变量保存数据并进行算术运算
"""

a = 321
b = 123

print('a + b = ', a + b)
print('a - b = ', a - b)
print('a * b = ', a * b)
print('a / b = ', a / b)
print('a // b = ', a // b)
print('a % b = ', a % b)
print('a ** b = ', a ** b)


"""
使用input函数输入
使用int()进行类型转换
用占位符格式化输出的字符串
"""
a = int(input('a = '))
b = int(input('b = '))
print(a + b)
print(a - b)
print(a * b)
print(a / b)
print(a // b)
print(a % b)
print(a ** b)


"""
格式化输出
"""
a = int(input('a = '))
b = int(input('b = '))
print('%d + %d = %d' % (a, b, a + b))
print('%d - %d = %d' % (a, b, a - b))
print('%d * %d = %d' % (a, b, a * b))
print('%d / %d = %f' % (a, b, a / b))
print('%d // %d = %d' % (a, b, a // b))
print('%d %% %d = %d' % (a, b, a % b))
print('%d ** %d = %d' % (a, b, a ** b))


"""
使用type()检查变量的类型
"""

a = 100
b = 12.345
c = 1 + 5j
d = 'hello, world'
e = True
print(type(a)) # int
print(type(b)) # float
print(type(c)) # complex
print(type(d)) # str
print(type(e)) # bool

# int()：将一个数值或字符串转换成整数，可以指定进制
# float()：将一个字符串转换成浮点数
# str()：将指定的对象转换成字符串形式，可以指定编码
# chr()：将整数转换成该编码对应的字符串（一个字符）
# ord()：将字符串（一个字符）转换成对应的编码（整数）

"""
类型转换
"""

a = 100
b = str(a)
c = 12.345
d = str(c)
e = '123'
f = int(e)
g = '123.456'
h = float(g)
i = False
j = str(i)
k = 'hello'
m = bool(k)
print(a)
print(type(a))
print(b)
print(type(b))
print(c)
print(type(c))
print(d)
print(type(d))
print(e)
print(type(e))
print(f)
print(type(f))
print(g)
print(type(g))
print(h)
print(type(h))
print(i)
print(type(i))
print(j)
print(type(j))
print(k)
print(type(k))
print(m)
print(type(m))


# 运算符
# 下面按优先级从高到低的顺序列出了所有的运算符
# 运算符      描述
# [] [:]     下标，切片
# **         指数
# ~ + -      按位取反，正负号
# * / % //   乘，除，模，整除
# + -        加，减
# >> <<      右移，左移
# &          按位与
# ^ |        按位异或，按位或
# <= < > >=  小于等于，小于，大于，大于等于
# == ！=     等于，不等于
# is is not  身份运算符
# in not in  成员运算符
# not or and 逻辑运算符
# = += -= *= /= %= //= **= &= |= ^= >>= <<=  （复合）赋值运算符

"""
运算符的使用
"""

a = 5
b = 10
c = 3
d = 4
e = 5
a += b
a -= c
a *= d
a /= e
print("a = ", a)

flag1 = 3 > 2
flag2 = 2 < 1
flag3 = flag1 and flag2
flag4 = flag1 or flag2
flag5 = not flag1
print("flag1 = ", flag1)
print("flag2 = ", flag2)
print("flag3 = ", flag3)
print("flag4 = ", flag4)
print("flag5 = ", flag5)
print(flag1 is True)
print(flag2 is not False)